package com.diankangwo.factory.controller;

import com.diankangwo.common.utils.PageUtils;
import com.diankangwo.common.utils.Query;
import com.diankangwo.common.utils.R;
import com.diankangwo.factory.entity.TdSpecial;
import com.diankangwo.factory.service.SpeciaService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 专题控制器
 */
@RestController
@RequestMapping("/fac/special")
public class SpeciaController {

    @Autowired
    private SpeciaService speciaService;

    /**
     * 专题加载列表
     *
     * @return
     */
    @ApiOperation(value = "专题加载列表", notes = "")
    @RequestMapping("/list")
    @RequiresPermissions("fac:special:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<TdSpecial> tdPortList = speciaService.queryList(query);
        int total = speciaService.queryTotal(query);
        PageUtils pageUtil = new PageUtils(tdPortList, total, query.getLimit(), query.getPage());
        return R.ok().put("page", pageUtil);
    }

    /**
     * 添加专题
     *
     * @return
     */
    @ApiOperation(value = "添加专题", notes = "")
    @RequestMapping("/add")
    @RequiresPermissions("fac:special:add")
    public R add(@RequestBody TdSpecial tdSpecial) {
        speciaService.insert(tdSpecial);
        return R.ok();
    }

    /**
     * 修改专题
     *
     * @return
     */
    @ApiOperation(value = "修改专题", notes = "")
    @RequestMapping("/update")
    @RequiresPermissions("fac:special:update")
    public R update(@RequestBody TdSpecial tdSpecial) {
        speciaService.updateByPrimaryKey(tdSpecial);
        return R.ok();
    }

    /**
     * 删除专题
     *
     * @return
     */
    @ApiOperation(value = "删除专题", notes = "")
    @RequestMapping("/delete")
    @RequiresPermissions("fac:special:delete")
    public R delete(@RequestParam Integer id) {
        speciaService.deleteByPrimaryKey(id);
        return R.ok();
    }

}
